/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package factoryTotal;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;

/**
 *
 * @author raul DisparoBomba
 */
public class DisparoBomba extends Disparo{

    Image bomb;
    Image exBomb;
    DisparoBomba db;
    int cnt = 0;
    float rango = 0;

    public DisparoBomba(float dany, Image bomb, Image exBomb) {
        super(dany);
        this.bomb = bomb;
        this.exBomb = exBomb;
    }
/**
     * Canvia la posicio del projectil
     * @param pX
     * @param pY
     */
    @Override
    public void posicion(float posX, float posY) {
        if(!(posY <= rango)){
            super.posicion(posX, posY);
            super.s = new Rectangle(posX, posY, bomb.getWidth(), bomb.getHeight());
        } else {
            super.posicion(posX, posY);
            Shape shape = new Rectangle(posX-100, posY-100, exBomb.getWidth(), exBomb.getHeight());
            super.s = shape;
        }
    }


    /**
     * Rederitza el projectil
     * @param gc
     * @param g
     */
    @Override
    public void render(GameContainer gc, Graphics g) {
        g.drawRect(pX-100, pY-100, exBomb.getWidth(), exBomb.getHeight());
        if(!(pY <= rango)){
            g.drawImage(bomb, pX, pY);
        }else {
            g.drawImage(exBomb, pX-100, pY-100);
        }
    }

    /**
     * Copia el projectil
     * @return projectil clonat
     */
    @Override
    public Disparo copiarDisparo() {
        return new DisparoBomba(daño, bomb, exBomb);
    }

    /**
     * Getter projectil clonat
     * @return projectil
     */
    public Disparo clonarDisparo() {
        Disparo p = (Disparo) copiarDisparo();
        p.posicion(pX, pY);
        return p;
    }

    /**
     * Genera impacte
     */
    public void impacto() {
        this.destruido = true;
    }

    public Image getBalaW() {
        return bomb;
    }

    @Override
    public void update(int delta){
        if(!(destruido)){
            if (pY <= 40){
                pY = 39;
                pX = 1300;
            } else if(pY <= rango){
                pY = rango;
                s.setLocation(pX, pY);
                posicion(pX, pY);
                cnt++;
                if ( cnt == 5) destruido = true;
            } else {
                pY -= 10;
                s.setLocation(pX, pY);

            }
        } else {
            pY = 0;
            pX = 1300;
                s.setLocation(pX, pY);

        }
    }

    public void setRango(float rango) {
        this.rango = rango-300;
    }

}
